
#ifndef CHESS_CONTROLLER_IMPL_H
#define CHESS_CONTROLLER_IMPL_H

#include "ChessController.h"
#include "ChessModel.h"
#include <Chess.h>
#include <HumanPlayer.h>
#include <CompPlayer.h>

class ChessControllerImpl : public ChessController{
   public:

      //! Constructor
      ChessControllerImpl();

      ~ChessControllerImpl();

      /**
	* Indicate to the player that the user clicked on the given
	* row and column with the mouse.
	*/
      void on_CellSelected(int row, int col, int button);

      ///@param row where drag began
      ///@param col where drag began
      void on_DragStart(int row,int col);

      ///@param row where drag ended
      ///@param col where drag ended
      ///@return true if the drag resulted in a successful drop
      bool on_DragEnd(int row,int col);

      /**
	* Handle when the user selected the new game button.
	*/
      void on_NewGame();

      /**
	* Handle when the user selected the save game button.
	*/
      void on_SaveGame();

      /**
	* Handle when the user selected the save game as button.
	*/
      void on_SaveGameAs();

      /**
	* Handle when the user selected the load game button.
	*/
      void on_LoadGame();

      /**
	* Handle when the user selected the undo move button.
	*/
      void on_UndoMove();

      /**
	* Handle when the user selects to quit the game, either through the
	* quit button, the close X button, or the file menu.
	*/
      void on_QuitGame();

      /**
	* Handle when a timer event has been signaled.
	*/
      void on_TimerEvent();

      /**
	* Set the ChessView that this ChessController will handle inputs for.
	*/
      void SetView(ChessView* view);

      void DrawBoard();

      void DrawSquare(BoardPosition pos);

      int GetType(Piece& curPiece);

      ChessPlayer * GetCurrentPlayer() const {
         return currentPlayer;
      }

      bool IsWhiteTurn () const {
         return currentPlayer == player1;
      }

      void NextPlayer() {
        void UnHighlightAll();
        void UnHighlightAll();
        void UnHighlightAll();
        void Initialize();
         currentPlayer = (currentPlayer == player1 ? player2 : player1);
      }

   private:
      ChessModel * model;
      ChessView * view;
      bool highlight;
      BoardPosition highPos;
      ChessPlayer * player1;
      ChessPlayer * player2;
      ChessPlayer * currentPlayer;
      void UnHighlightAll();
      void Destroy();
      void Initialize();
      bool IsPlayersPiece(Piece* curPiece);
};

#endif

